﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SilverTile;
using System.Windows.Media.Imaging;

namespace SilverTileTests
{

    [TestClass]
    public class FrameTests
    {

        [TestMethod]
        public void Frame_Should_Have_A_Size()
        {

            int expectedWidth = 32;
            int expectedHeight = 40;

            IFrame frame = new Frame(expectedWidth, expectedHeight);

            Assert.AreEqual(expectedWidth, frame.Width, "Frame width was not set correctly");
            Assert.AreEqual(expectedHeight, frame.Height, "Frame height was not set correctly");
            Assert.AreEqual(expectedWidth * expectedHeight, frame.Pixels.Length, "Frame pixels array is not of the right size");

        }

        [TestMethod]
        public void Frame_Should_Be_Creatable_From_An_Image()
        {

            string imgUri = "/SilverTileTests;component/Tiles/0002.png";

            IFrame frame = new Frame(imgUri);

            BitmapImage img = new BitmapImage();
            img.SetSource(Application.GetResourceStream(new Uri(imgUri,UriKind.Relative)).Stream);
            WriteableBitmap wb = new WriteableBitmap(img);

            Assert.AreEqual(wb.PixelWidth, frame.Width, "Frame width was not set correctly");
            Assert.AreEqual(wb.PixelHeight, frame.Height, "Frame height was not set correctly");
            CollectionAssert.AreEqual(wb.Pixels, frame.Pixels, "Frame pixels are not equal to source images pixels");
            
        }

        [TestMethod]
        public void Frame_Should_Have_Default_Origin_At_0_0()
        {
            IFrame frame = new Frame(20,20);

            Assert.AreEqual(0, frame.OriginX, "Default OriginX was not 0");
            Assert.AreEqual(0, frame.OriginY, "Default OriginY was not 0");

        }

        [TestMethod]
        public void Frame_Should_Have_Settable_Origin()
        {


            int originX = 10, originY = 20;

            IFrame frame = new Frame(30,30)
            {
                OriginX = originX,
                OriginY = originY
            };

            Assert.AreEqual(originX, frame.OriginX, "OriginX was not set correctly");
            Assert.AreEqual(originY, frame.OriginY, "OriginY was not set correctly");

        }

    }
}
